import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { UserVO } from '@/types/result'
import type { PageDTO, PlayListItem, SongsPageDTO } from '@/types/song'

export const useUserStore = defineStore(
  'userStore',
  () => {
    const token = ref<string | null>(null)
    const userVO = ref<UserVO | null>(null)
    const songsList = ref<PlayListItem[]>([])
    const songsListPosition = ref<number>(0)
    const isOpen = ref<boolean>(false)
    const favoriteList = ref<PageDTO<SongsPageDTO[]> | null>()

    function $reset() {
      token.value = null
      userVO.value = null
      songsListPosition.value = 0
      songsList.value = []
      isOpen.value = false
      favoriteList.value = null
    }

    return { token, userVO, songsList, songsListPosition, favoriteList, isOpen, $reset }
  },
  {
    persist: {
      pick: ['userVO', 'token', 'songsList', 'songsListPosition', 'favoriteList'],
    },
  }
)
